<body class="gr">

<div class="navBar">
    <a class="left" href="wap.php"><i class="return"></i></a>
    <div class="titleView-x">限量抢购</div>
</div>

<div class="goods-purchase main-padding-top">
	<div class="pullRefresh">
		<ul class="list">
			{foreach from=$data.goods name=g item=g}
			<li>
				<a href="wap.php?app=goods&act=detail&id={$g->id}&purchase=1">
					<div class="pic" style="background-image:url({$g->pic});"></div>
					<div class="right">
						<div class="name">{$g->name}</div>
						<div class="bottom-left">
							<span>¥{number_format($g->price,2)}</span><s>¥{number_format($g->market_price,2)}</s>
							<div class="progress">
								<div style="width:{number_format($g->purchased/$g->purchase_count*100,1)}%;"></div>
								<span>剩余{number_format($g->purchased/$g->purchase_count*100,1)}%</span>
							</div>
						</div>
						<div class="btn">马上抢</div>
					</div>
				</a>
			</li>
			{/foreach}
		</ul>
	</div>
</div>
<script>
var offset = $('.pullRefresh .list > li').length;
function createHtml(g){
	var html = '<li>\
		<a href="wap.php?app=goods&act=detail&id='+g.id+'">\
			<div class="pic" style="background-image:url('+g.pic+');"></div>\
			<div class="right">\
				<div class="name">'+g.name+'</div>\
				<div class="bottom-left">\
					<span>¥'+g.price.numberFormat(2)+'</span><s>¥'+g.market_price.numberFormat(2)+'</s>\
					<div class="progress">\
						<div style="width:'+(g.purchased.accDiv(g.purchase_count)*100).numberFormat(1)+'%;"></div>\
						<span>剩余'+(g.purchased.accDiv(g.purchase_count)*100).numberFormat(1)+'%</span>\
					</div>\
				</div>\
				<div class="btn">马上抢</div>\
			</div>\
		</a>\
	</li>';
	offset++;
	return html;
}
$(function(){
	$('html, body, .pullRefresh').addClass('height-wrap');
	$('.goods-purchase').height($.window().height-$('.goods-purchase').padding().top);
	$('.pullRefresh').pullRefresh({
		header : true,
		footer : true,
		footerNoMoreText : '- END -',
		refresh : function(fn){
			var _this = this;
			offset = 0;
			$.getJSON('api.php?app=goods&act=index&purchase=1', function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data.goods))for(var i=0; i<json.data.goods.length; i++)html += createHtml(json.data.goods[i]);
				_this.find('.list').html(html);
				fn();
			});
		},
		load : function(fn){
			var _this = this;
			$.getJSON('api.php?app=goods&act=index&purchase=1', { offset:offset }, function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data.goods))for(var i=0; i<json.data.goods.length; i++)html += createHtml(json.data.goods[i]);
				_this.find('.list').append(html);
				fn();
			});
		}
	});
});
</script>